package _1_5_type_convert;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import _1_2_ClassAndObject.User;
import org.junit.Test;

/**
 * Created by bpzj on 9/29/2018.
 */
public class JavaBeanToJsonString {

    @Test
    public void useJackson() {
        User user = new User();
        user.setAge(1);
        user.setHeight(12);
        user.setName("sy");
        //创建ObjectMapper
        ObjectMapper mapper = new ObjectMapper();
        //输出到内存
        try {
            String jsonStr = mapper.writeValueAsString(user);
            System.out.println(jsonStr);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }


    }

}
